function main() {
    debugger;
    var self = this;

    var formPartEle = self.$$("form_part_d9n5t7");

    let btnSubmitEle = this.$$("form_submit_button_mobile_fnx9vv");
    let btnSubmitTitle = btnSubmitEle.data.props.operateItem.title;
    var formRenderEle = formPartEle && formPartEle.$$getRenderElement();

    if (!formRenderEle) {
        console.error("未找到表单渲染元素");
        return;
    }

    formRenderEle.onSave().then(function (res) {
        if (!res || !res.result) {
            console.error("保存操作失败或未返回结果");
            return;
        }

        console.log("保存成功", res);
        processSaveResult(res.result)
            .then(function () {
                if (btnSubmitTitle === '提交') {
                    openCaseSourceModal(self);
                } else {
                    // 转案件相关页面
                    let urlBase = api.CONST["bd_var:07bb31e3-e15c-4b1b-ac48-400bc5a1ba8d"];
                    const applicationId = self.state.applicationId;
                    const tokenKey = `${applicationId}:access_token`;
                    const casKey = `${applicationId}:cas_access_token`;
                    const token = getParameter('token') || localStorage.getItem(casKey) || localStorage.getItem(tokenKey) || "";
                    let caseRegister = urlBase + "?egova_token=" + token + "#/case-register?sourceId=" + res.result.documentNo;
                    console.log('caseRegister')
                    window.open(caseRegister, "_self");
                }
            })
            .catch(function (error) {
                console.error("处理保存结果时出错:", error);
            });
    }).catch(function (error) {
        console.error("保存操作过程中出错:", error);
    });
}

function processSaveResult(result) {
    return new Promise(function (resolve, reject) {
        var caseIdValue = result.documentNo;
        var caseData = result.root_cuhejk;
        var disposalTypeValue = caseData.single_select_95sw6u;
        var litigantIdValue = caseData.widget_list_picker_669p9a;
        var penaltyFlagValue = disposalTypeValue === '3' ? '1' : '0';

        var params = [{
            name: "litigantId",
            valueContent: litigantIdValue
        }];

        api.DATA_SOURCE_EXECUTE(
            "ds_mod:467c2d03-36d1-41ea-b01e-5fc9c01eaea3",
            "ddcat",
            params,
            [],
            ""
        ).then(function (dsResponse) {
            debugger;
            updateDisposalInfo(caseIdValue, caseData, litigantIdValue, penaltyFlagValue, dsResponse)
                .then(resolve)
                .catch(reject);
        }).catch(function (err) {
            console.error("执行数据源查询失败:", err);
            reject(err);
        });
    });
}

function updateDisposalInfo(caseId, caseData, litigantId, penaltyFlag, dsResponse) {
    var caseViolationCountValue = parseInt(dsResponse.result[0].case_violation_count) || 0;
    var casePenaltyCountValue = parseInt(dsResponse.result[0].case_penalty_count) || 0;

    if (penaltyFlag === '1') {
        casePenaltyCountValue += 1;
    } else {
        caseViolationCountValue += 1;
    }

    var disposalInfoData = {
        caseId: caseId,
        litigantId: litigantId,
        disposalType: caseData.single_select_95sw6u,
        disposalDesc: caseData.textarea_158prq,
        penaltyFlag: penaltyFlag,
        relateRecId: '',
        caseViolationCount: caseViolationCountValue,
        casePenaltyCount: casePenaltyCountValue
    };

    return insertLawCaseRelDisposalInfo(disposalInfoData);
}

function insertLawCaseRelDisposalInfo(disposalInfoData) {
    var insertLawCaseRelDisposalInfoSql = [
        ['case_source_info_id', disposalInfoData.caseId],
        ['litigant_id', "'" + disposalInfoData.litigantId + "'"],
        ['disposal_type', "'" + disposalInfoData.disposalType + "'"],
        ['disposal_desc', "'" + disposalInfoData.disposalDesc + "'"],
        ['penalty_flag', "'" + disposalInfoData.penaltyFlag + "'"],
        ['relate_rec_id', "'" + disposalInfoData.relateRecId + "'"],
        ['case_violation_count', "'" + disposalInfoData.caseViolationCount + "'"],
        ['case_penalty_count', "'" + disposalInfoData.casePenaltyCount + "'"],
        ['create_time', 'NOW()']
    ];

    var formattedFields = insertLawCaseRelDisposalInfoSql.map(function (field) {
        return "'" + field[0] + "'," + field[1];
    });

    var law_case_rel_disposal_info = "ds_tbl:t_831bab5d588846a7b16edd07acd25608";
    var insertSql = "INSERT('" + law_case_rel_disposal_info + "', [" + formattedFields.join(',') + "])";
    console.log("准备执行的SQL语句:", insertSql);

    return new Promise(function (resolve, reject) {
        api.EXEC_FORMULA(insertSql)
            .then(function (res) {
                console.log("数据插入成功");
                resolve(res);
            })
            .catch(function (err) {
                console.error("数据插入失败:", err);
                reject(err);
            });
    });
}

function openCaseSourceModal(self) {
    self.$router.push({
        name: "page-preview",
        query: {
            title: "完成上报",
            pageId: '1952283059282886656',
            showHeader: self.$route.query.showHeader,
            pageTitle: "完成上报",
            linkTitle: '完成上报',
            showBackHeade: true,
            isFromAction: 1,
            _t: new Date().getTime() + ""
        }
    });
}

/**
 * 截取参数
 */
function getParameter(key) {
    const reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
    const match = window.location.href.match(reg);

    if (match) {
        return unescape(match[2]);
    }
    return null;
}
